#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>
#include <functional>
#include <memory>
using namespace std;

class Solution {
public:
    bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {
        unordered_map<int, vector<int>> map;
        vector<int> in(numCourses, 0);

        for (auto e : prerequisites)
        {
            in[e[0]]++;
            map[e[1]].push_back(e[0]);
        }

        queue<int> qt;
        for (int i = 0; i < in.size(); i++)
        {
            if (in[i] == 0)
                qt.push(i);
        }
        while (qt.size())
        {
            int num = qt.front();
            qt.pop();
            for (auto& e : map[num])
            {
                in[e]--;
                if (in[e] == 0) qt.push(e);
            }
        }

        for (int i = 0; i < in.size(); i++)
        {
            if (in[i] != 0) return false;
        }

        return true;
    }
};

int main()
{
	return 0;
}